<template>
    <el-button type="primary" @click="handleClick">
        <slot></slot>
    </el-button>
</template>
<script>
import { pay } from "common/src/api/payment";
import { strengthenClassPayValidate } from "common/src/api/strengtheningclass/scMyStrengthClassInfo";

/**
 * 支付组件<本科生语言强化班报名缴费组件>
 */
export default {
    name: "PaymentButton",
    model: { event: "click" },
    props: {
        params: {
            type: Object,
            default: { studentId: "", scTypeCode:"", schoolYear:"", registId:"", feeItemCode: "", callBackData: { "id": "强化班缴费"}},
        }
    },
    data() {
        return {};
    },
    mounted() {},
    created() {},
    methods: {

        handleClick() {
            console.log(this.params);
            // this.$emit("click", null);
            let { studentId, scTypeCode, schoolYear, registId, feeItemCode, callBackData } = this.params;
            if (studentId !== undefined && studentId !== "" && feeItemCode !== undefined && feeItemCode !== "" ) {

                // 强化班学生缴费数据校验接口-add by quanwei
                strengthenClassPayValidate(studentId, scTypeCode, schoolYear, registId).then(res => {
                    if (res.code == 200) {
                        this.handlePay(this.params); // 缴费接口
                    }else{
                        this.$message({ type: "error", message: errorMsg });
                    }
                });
            } else {
                let id = "studentId";
                if (studentId) {
                    id = "feeItemCode";
                }
                this.$message({ message: `${id}字段不能为空`, type: "warning" });
            }
        },

        handlePay(data) {
            pay(data).then(res => {
                if (res.code == 200) {
                    // console.log(JSON.stringify(res), "111");
                    
                    top.location.href = res.data; // 跳转
                    //window.open(`${res.data}`);             // 新开窗口
                    //暂未实现                                // 弹窗
                }
            }).catch(res => {
                console.log(res);
            });
        }

    }
};
</script>

<style scoped>
</style>
